home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / windows4 / prndrv.zip / INIT.C < prev    next >
Text File  |  1992-02-20  |  4KB  |  141 lines

  1. //*************************************************************
  2. //  File name: init.c
  3. //
  4. //  Description:
  5. //
  6. //      Contains the code to register the window class and create 
  7. //      main application window.
  8. //
  9. //
  10. // Development Team:
  11. //
  12. //      Don Miller
  13. //
  14. //
  15. // Written by Microsoft Product Support Services, Windows Developer Support
  16. // Copyright (c) 1992 Microsoft Corporation. All rights reserved.
  17. //*************************************************************
  18.  
  19. // The following #define is used by GLOBALS.H -- it tells it that we
  20. //  want the globals _declared_ in this module.
  21.  
  22. #define IN_INIT
  23. #include <windows.h>
  24. #include "globals.h"
  25. #include "mainwnd.h"
  26. #include "init.h"
  27.  
  28.  
  29.  
  30. // Default string length.
  31.  
  32. #define STR_LEN   50
  33.  
  34.  
  35.  
  36. //-----------------------------------------------------------------------
  37. //  Function: InitApplication
  38. //
  39. //  Purpose : Called by WinMain on first instance of app.  Registers
  40. //            the window class.
  41. //
  42. //  Parms   : hInst == Handle to _this_ instance.
  43. //
  44. //  Returns : TRUE on success, FALSE otherwise.
  45. //-----------------------------------------------------------------------
  46.  
  47.  
  48. BOOL InitApplication (HANDLE hInst)
  49. {
  50.    WNDCLASS  wc;
  51.    char      szMenuName [STR_LEN];
  52.    char      szClassName [STR_LEN];
  53.  
  54.  
  55.    LoadString (hInst, IDS_MAINMENUNAME,  szMenuName,  STR_LEN);
  56.    LoadString (hInst, IDS_MAINCLASSNAME, szClassName, STR_LEN);
  57.  
  58.    wc.style          = CS_HREDRAW |
  59.                        CS_VREDRAW;
  60.    wc.lpfnWndProc    = MainWndProc;
  61.    wc.cbClsExtra     = 0;
  62.    wc.cbWndExtra     = 0;
  63.    wc.hInstance      = hInst;
  64.    wc.hIcon          = LoadIcon (NULL, IDI_APPLICATION);
  65.    wc.hCursor        = LoadCursor (NULL, IDC_ARROW);
  66.    wc.hbrBackground  = COLOR_WINDOW + 1;
  67.    wc.lpszMenuName   = szMenuName;
  68.    wc.lpszClassName  = szClassName;
  69.  
  70.  
  71.       // Register the window class and return success/failure code.
  72.  
  73.    return RegisterClass(&wc);
  74. }
  75.  
  76. //-----------------------------------------------------------------------
  77. //  Function: InitInstance
  78. //
  79. //  Purpose : Called by WinMain on instance startup.  Creates and
  80. //            displays the main, overlapped window.
  81. //
  82. //  Parms   : hInstance     == Handle to _this_ instance.
  83. //            nCmdShow      == How app should come up (i.e. minimized/normal)
  84. //
  85. //  Returns : TRUE on success, FALSE otherwise.
  86. //-----------------------------------------------------------------------
  87.  
  88. BOOL InitInstance(HANDLE hInstance, 
  89.                   int    nCmdShow)
  90. {
  91.    HWND hWnd;
  92.    char szTitle [STR_LEN];
  93.    char szClassName [STR_LEN];
  94.  
  95.  
  96.  
  97.       // Load some necessary strings from the string table.
  98.  
  99.    LoadString (hInstance, IDS_PROGNAME,      szTitle,     STR_LEN);
  100.    LoadString (hInstance, IDS_MAINCLASSNAME, szClassName, STR_LEN);
  101.  
  102.  
  103.       // Save the instance handle in static variable, which will be used in
  104.       // many subsequence calls from this application to Windows.          
  105.  
  106.    ghInst = hInstance;
  107.  
  108.  
  109.       // Create a main window for this application instance.
  110.  
  111.    hWnd = CreateWindow (szClassName,      // See RegisterClass() call.
  112.       szTitle,                            // Text for window title bar.
  113.       WS_OVERLAPPEDWINDOW,                // Window style.
  114.       CW_USEDEFAULT,                      // Default horizontal position.
  115.       CW_USEDEFAULT,                      // Default vertical position.
  116.       CW_USEDEFAULT,                      // Default width.
  117.       CW_USEDEFAULT,                      // Default height.
  118.       NULL,                               // Overlapped windows have no parent.
  119.       NULL,                               // Use the window class menu.        
  120.       hInstance,                          // This instance owns this window.   
  121.       NULL);                              // Pointer not used.               
  122.  
  123.  
  124.       // We'll keep a global of the main window's handle.  This is useful
  125.       //  for calls to MessageBox(), etc.
  126.  
  127.    ghWnd = hWnd;
  128.  
  129.  
  130.       // If window could not be created, return "failure"
  131.  
  132.    if (!hWnd)
  133.       return (FALSE);
  134.  
  135.  
  136.       // Make the window visible; update its client area; and return "success"
  137.  
  138.    ShowWindow (hWnd, nCmdShow);           // Show the window                        
  139.    UpdateWindow (hWnd);                   // Sends WM_PAINT message
  140. }
  141.